from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-25 14:02:20.142503
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 25, Sep, 2022
Time: 14:02:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5155
Nobs: 790.000 HQIC: -50.8432
Log likelihood: 10165.2 FPE: 6.76476e-23
AIC: -51.0477 Det(Omega_mle): 6.04069e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300766 0.053703 5.601 0.000
L1.Burgenland 0.108948 0.035788 3.044 0.002
L1.Kärnten -0.106420 0.019044 -5.588 0.000
L1.Niederösterreich 0.208462 0.074841 2.785 0.005
L1.Oberösterreich 0.102538 0.071891 1.426 0.154
L1.Salzburg 0.251713 0.038204 6.589 0.000
L1.Steiermark 0.038523 0.049954 0.771 0.441
L1.Tirol 0.106080 0.040488 2.620 0.009
L1.Vorarlberg -0.060035 0.034820 -1.724 0.085
L1.Wien 0.053703 0.064359 0.834 0.404
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062608 0.111356 0.562 0.574
L1.Burgenland -0.033318 0.074209 -0.449 0.653
L1.Kärnten 0.048150 0.039488 1.219 0.223
L1.Niederösterreich -0.172653 0.155187 -1.113 0.266
L1.Oberösterreich 0.385850 0.149070 2.588 0.010
L1.Salzburg 0.286534 0.079219 3.617 0.000
L1.Steiermark 0.107849 0.103582 1.041 0.298
L1.Tirol 0.312618 0.083954 3.724 0.000
L1.Vorarlberg 0.025912 0.072201 0.359 0.720
L1.Wien -0.016826 0.133453 -0.126 0.900
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192266 0.027579 6.971 0.000
L1.Burgenland 0.089948 0.018379 4.894 0.000
L1.Kärnten -0.008296 0.009780 -0.848 0.396
L1.Niederösterreich 0.263495 0.038435 6.856 0.000
L1.Oberösterreich 0.127178 0.036920 3.445 0.001
L1.Salzburg 0.046960 0.019620 2.393 0.017
L1.Steiermark 0.018318 0.025654 0.714 0.475
L1.Tirol 0.093685 0.020793 4.506 0.000
L1.Vorarlberg 0.058584 0.017882 3.276 0.001
L1.Wien 0.118816 0.033052 3.595 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108808 0.028246 3.852 0.000
L1.Burgenland 0.044588 0.018823 2.369 0.018
L1.Kärnten -0.015826 0.010016 -1.580 0.114
L1.Niederösterreich 0.192729 0.039364 4.896 0.000
L1.Oberösterreich 0.294457 0.037812 7.787 0.000
L1.Salzburg 0.114359 0.020094 5.691 0.000
L1.Steiermark 0.101628 0.026274 3.868 0.000
L1.Tirol 0.115311 0.021295 5.415 0.000
L1.Vorarlberg 0.071174 0.018314 3.886 0.000
L1.Wien -0.027510 0.033851 -0.813 0.416
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131987 0.051164 2.580 0.010
L1.Burgenland -0.051684 0.034097 -1.516 0.130
L1.Kärnten -0.040219 0.018144 -2.217 0.027
L1.Niederösterreich 0.171270 0.071303 2.402 0.016
L1.Oberösterreich 0.139181 0.068493 2.032 0.042
L1.Salzburg 0.285980 0.036398 7.857 0.000
L1.Steiermark 0.035910 0.047593 0.755 0.451
L1.Tirol 0.163665 0.038574 4.243 0.000
L1.Vorarlberg 0.102283 0.033174 3.083 0.002
L1.Wien 0.063803 0.061317 1.041 0.298
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059339 0.040606 1.461 0.144
L1.Burgenland 0.038440 0.027060 1.421 0.155
L1.Kärnten 0.051099 0.014400 3.549 0.000
L1.Niederösterreich 0.223024 0.056589 3.941 0.000
L1.Oberösterreich 0.283626 0.054359 5.218 0.000
L1.Salzburg 0.049193 0.028887 1.703 0.089
L1.Steiermark -0.004524 0.037772 -0.120 0.905
L1.Tirol 0.148400 0.030614 4.847 0.000
L1.Vorarlberg 0.072576 0.026328 2.757 0.006
L1.Wien 0.079792 0.048664 1.640 0.101
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181424 0.048539 3.738 0.000
L1.Burgenland -0.006036 0.032347 -0.187 0.852
L1.Kärnten -0.061081 0.017213 -3.549 0.000
L1.Niederösterreich -0.082744 0.067645 -1.223 0.221
L1.Oberösterreich 0.193111 0.064978 2.972 0.003
L1.Salzburg 0.056553 0.034531 1.638 0.101
L1.Steiermark 0.232255 0.045151 5.144 0.000
L1.Tirol 0.493503 0.036595 13.486 0.000
L1.Vorarlberg 0.048059 0.031472 1.527 0.127
L1.Wien -0.052797 0.058171 -0.908 0.364
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162627 0.055775 2.916 0.004
L1.Burgenland -0.011436 0.037169 -0.308 0.758
L1.Kärnten 0.066394 0.019778 3.357 0.001
L1.Niederösterreich 0.198689 0.077728 2.556 0.011
L1.Oberösterreich -0.060268 0.074664 -0.807 0.420
L1.Salzburg 0.214194 0.039678 5.398 0.000
L1.Steiermark 0.115955 0.051881 2.235 0.025
L1.Tirol 0.074949 0.042050 1.782 0.075
L1.Vorarlberg 0.124497 0.036163 3.443 0.001
L1.Wien 0.116508 0.066842 1.743 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360894 0.032319 11.167 0.000
L1.Burgenland 0.006804 0.021538 0.316 0.752
L1.Kärnten -0.023155 0.011461 -2.020 0.043
L1.Niederösterreich 0.220823 0.045040 4.903 0.000
L1.Oberösterreich 0.178140 0.043265 4.117 0.000
L1.Salzburg 0.045223 0.022992 1.967 0.049
L1.Steiermark -0.016443 0.030063 -0.547 0.584
L1.Tirol 0.107041 0.024366 4.393 0.000
L1.Vorarlberg 0.072236 0.020955 3.447 0.001
L1.Wien 0.049465 0.038733 1.277 0.202
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041192 0.151115 0.191133 0.155772 0.125503 0.112365 0.065432 0.223324
Kärnten 0.041192 1.000000 -0.002842 0.129154 0.041494 0.095509 0.430419 -0.053780 0.101485
Niederösterreich 0.151115 -0.002842 1.000000 0.336576 0.152291 0.300442 0.107862 0.182727 0.324784
Oberösterreich 0.191133 0.129154 0.336576 1.000000 0.231879 0.332163 0.171920 0.171214 0.263295
Salzburg 0.155772 0.041494 0.152291 0.231879 1.000000 0.146801 0.123507 0.148789 0.133605
Steiermark 0.125503 0.095509 0.300442 0.332163 0.146801 1.000000 0.153022 0.139809 0.079558
Tirol 0.112365 0.430419 0.107862 0.171920 0.123507 0.153022 1.000000 0.114099 0.152388
Vorarlberg 0.065432 -0.053780 0.182727 0.171214 0.148789 0.139809 0.114099 1.000000 0.004194
Wien 0.223324 0.101485 0.324784 0.263295 0.133605 0.079558 0.152388 0.004194 1.000000